package ltd.service;

import java.util.List;

import javax.annotation.Resource;

import ltd.dao.UserDao;
import ltd.entity.User;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.googlecode.genericdao.search.Search;

@Service(value="userService")
@Scope("singleton")
@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
public class UserService {
	
	@Resource 
	private UserDao userDao;

	@Transactional(readOnly=false, propagation=Propagation.REQUIRED)
	public boolean save(User user) {
		return this.userDao.save(user);
	}

	@Transactional(readOnly=false, propagation=Propagation.REQUIRED)
	public boolean[] save(User[] users) {
		return this.userDao.save(users);
	}

	@Transactional(readOnly=false, propagation=Propagation.REQUIRED)
	public boolean remove(User user) {
		return this.userDao.remove(user);
	}

	@Transactional(readOnly=false, propagation=Propagation.REQUIRED)
	public void remove(User[] users) {
		this.userDao.remove(users);
	}

	@Transactional(readOnly=false, propagation=Propagation.REQUIRED)
	public boolean removeById(Integer id) {
		return this.userDao.removeById(id);
	}

	@Transactional(readOnly=false, propagation=Propagation.REQUIRED)
	public void removeByIds(Integer[] ids) {
		this.userDao.removeByIds(ids);
	}

	public List<User> findAll() {
		return this.userDao.findAll();
	}

	public User findById(Integer id) {
		return this.userDao.find(id);
	}

	public User[] findByIds(Integer[] ids) {
		return this.userDao.find(ids);
	}

	public int count(Search search) {
		return this.userDao.count(search);
	}

	public List<User> search(Search search) {
		return this.userDao.search(search);
	}
	
	public User searchOne(Search search) {
		return this.userDao.searchUnique(search);
	}

	public void flush() {
		this.userDao.flush();
	}
}
